﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class SessionTest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ArrayList list = new ArrayList();
        Session["LIST"] = list;
        Session["ValueDictionary"] = new Dictionary<string, string>();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        ArrayList list = (ArrayList)Session["LIST"];
        list.Add(DateTime.Now.ToString());
        ShowMsg("Add sucessfully!");
    }
    protected void btnGet_Click(object sender, EventArgs e)
    {
        ArrayList list = (ArrayList)Session["LIST"];
        foreach (var item in list)
        {
            divMsg.InnerHtml += item.ToString() + "<br>";
        }
        if (list.Count > 0)
        {
            ShowMsg(list[list.Count - 1].ToString());
        }
    }
    public void ShowMsg(string msg)
    {
        Page.ClientScript.RegisterClientScriptBlock(GetType(), "msg", string.Format("<script>alert('{0}')</script>", msg));
    }
}
